# 参考网址
# https://www.cnblogs.com/Peter2014/p/8065114.html

import requests
from lxml import etree
from selenium import webdriver
from selenium import webdriver
#
# options = webdriver.FirefoxOptions()
# options.add_argument('-headless')
# browser = webdriver.Firefox(options=options)


def geturl(url):
    # header={}
    response=requests.get(url=url)
    print('请求拿到的信息编码格式为 %s' %response.encoding)
    print('请求拿到的信息编码格式为 %s' %response.apparent_encoding)
    if response.encoding == 'ISO-8859-1':
        a=response.text.encode(response.encoding).decode(response.apparent_encoding)
        print('a====%s' %a)
        print(type(a))
        return a
    else:
        # print(str(response.text))
        print(response.content.decode('utf-8'))
        return response.text

def parsehtml(strhtml):
    html=etree.HTML(strhtml)
    titles=html.xpath('//*[@id="moderate"]/table/tbody/tr/th/a')
    print(titles[0].get('href'))
text1=geturl('https://www.imahua.tv/')
parsehtml(text1)